const { get_file_list } = require("../utils/file_tool");
const { BaseCommand } = require("./base");
const { toArray } = require("../utils/transform_tool");

class OpenCommand extends BaseCommand {
    async execute() {
        const open = require("open");
        const data = this.selfData;
        let urls;
        switch (data.mode) {
            case "web": {
                urls = toArray(data.src);
                break;
            }
            default: {
                urls = get_file_list(data.src);
            }
        }
        const options = Object.assign({ wait: true }, data.options);
        for (let index = 0; index < urls.length; index++) {
            const file = urls[index];
            await open(file, options);
        }
    }
}

module.exports = {
    OpenCommand,
};
